package com.example.wan1.login;

import android.util.Log;


import com.example.wan1.base.BasePresenter;
import com.example.wan1.data.RxSchedulers;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/***
 * 创建时间：2020/2/10 18:41
 * 创建人：10850
 * 功能描述：
 */

public class LoginPresenter extends BasePresenter<LoginContract.View> implements LoginContract.Presenter {

    @Override
    public void login() {
        if (isViewAttached()) {
//            getView().showLoading();
            Log.i("login", "login: " + mDataClient.provideData().toString());
            Log.i("login", "login: " + (mDataClient != null));

            mDataClient.provideData().postLogin(getView().getUserInfo().getData().getUsername(), getView().getUserInfo().getData().getPassword())
                    .compose(RxSchedulers.observableIO2Main())
                    .subscribe(new Observer<PersonBean>() {
                        @Override
                        public void onSubscribe(Disposable d) {

                        }

                        @Override
                        public void onNext(PersonBean personBean) {
                            getView().loginSuccess(personBean);
                        }

                        @Override
                        public void onError(Throwable e) {
                            getView().loginFailure("登录失败!");
                        }

                        @Override
                        public void onComplete() {
                            getView().loginFailure("登录完成!");
                        }
                    });

            /*RetrofitUtil.getInstance()
                    .postLogin(getView().getUserInfo().getData().getUsername(), getView().getUserInfo().getData().getPassword())
//                    .subscribeOn(Schedulers.io())
//                    .observeOn(AndroidSchedulers.mainThread())
                    .compose(RxSchedulers.observableIO2Main())
                    .subscribe(new Observer<PersonBean>() {
                        @Override
                        public void onSubscribe(Disposable d) {

                        }

                        @Override
                        public void onNext(PersonBean personBean) {
                            getView().loginSuccess(personBean);
                        }

                        @Override
                        public void onError(Throwable e) {
                            getView().loginFailure("登录失败!");
                        }

                        @Override
                        public void onComplete() {
                            getView().loginFailure("登录完成!");
                        }
                    });*/


        }
    }

    @Override
    public void start() {

    }
}